package com.qh.resourcehub.program.netmapping.controller;

import com.qh.resourcehub.program.dto.NetMappingDto;
import com.qh.resourcehub.program.netmapping.service.NetMappingService;
import com.qh.resourcehub.program.vo.NetMappingVo;
import com.qh.resourcehub.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//青海省气象信息中心网络地址对外映射申请表（数据服务室） 05
@RestController
@RequestMapping("/netMappingApply")
public class NetMappingApplyController {
    @Autowired
    private NetMappingService service;
    /*
     * @Description:
     * @param 查询申请信息
     * @return
     * @Author: Y6
     * @Date: 2025/4/18 14:19
     */
    @PostMapping("/queryNetMappingData")
    public ApiResponse queryNetMappingData(@RequestBody NetMappingDto dto) {
        try {
            List<NetMappingVo> data = service.queryNetMappingData(dto);
            if (data.size()>0){
                return ApiResponse.succeed(data);
            }else {
                return ApiResponse.succeedNoData();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("查询失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    /**
     * 申请新增
     * @param
     * @return
     */
    @PostMapping("/ApplicationSave")
    public ApiResponse ApplicationSave(@RequestBody NetMappingDto dto) {
        try {
            int i = service.ApplicationSave(dto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    /**
     * 申请修改
     * @param
     * @return
     */
    @PostMapping("/ApplicationUpdata")
    public ApiResponse ApplicationUpdata(@RequestBody NetMappingDto dataDto) {
        try {
            int i = service.ApplicationUpdata(dataDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }
    /**
     * 申请删除
     * @param
     * @return
     */
    @PostMapping("/Applicationdel")
    public ApiResponse Applicationdel(@RequestBody NetMappingDto dataDto) {
        try {
            int i = service.Applicationdel(dataDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    /**examine
     * 申请提交
     * @param
     * @return
     */
    @PostMapping("/ApplicationSubmit")
    public ApiResponse ApplicationSubmit(@RequestBody NetMappingDto dataDto) {
        try {
            int i = service.ApplicationSubmit(dataDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    /**
     * 申请撤回
     * @param
     * @return
     */
    @PostMapping("/ApplicationWithdraw")
    public ApiResponse ApplicationWithdraw(@RequestBody NetMappingDto dataDto) {
        try {
            int i = service.ApplicationWithdraw(dataDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }
}
